<?php

namespace app\admin\controller;

use app\admin\model\Userdata;
use think\Controller;
use think\Db;

class User extends Controller {

	/**
	 * 显示资源列表
	 *
	 * @return \think\Response
	 */
	// protected $field = true;

	public function member() {
		if (input('get.isDel') == 0) {
			if (input('get.name') != null) {
				$result = Userdata::withTrashed()->where('username', input('get.name'))->select();
			} else {
				$result = Userdata::withTrashed()->select();
			}
		} else {
			if (input('get.name') != null) {
				$result = Userdata::onlyTrashed()->where('username', input('get.name'))->select();
			} else {
				$result = Userdata::onlyTrashed()->select();
			}
		}
		echo json_encode($result);
	}
	/**
	 * 用户删除
	 * @return [type] [description]
	 */
	public function del() {
		if (!input('post.id')) {
			echo json_encode(['status' => '500']);die;
		} else {
			$id = input('post.id');
		}

		$user = Db::name('userdata')->where('id', $id)->update(['delete_time' => time()]);
		if ($user) {
			echo json_encode(['status' => '200']);
		} else {
			echo json_encode(['status' => '403']);
		}

	}

	public function destroy() {
		if (!input('post.id')) {
			echo json_encode(['status' => '500']);die;
		} else {
			$id = input('post.id');
		}
		$user = Userdata::destroy($id, true);
		if ($user) {
			echo json_encode(['status' => '200']);
		} else {
			echo json_encode(['status' => '403']);
		}

	}
	/**
	 * 更新用户数据
	 * @return [type] [description]
	 */
	public function update() {
		$user = new Userdata;
		$result = $user->withTrashed()->where('username', input('post.username'))->update(input('post.'));
		echo json_encode($result);
	}
}
